home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC12Menus / Menus.asm < prev    next >
Encoding:
Assembly Source File  |  1990-06-24  |  42.1 KB  |  1,216 lines  |  [TEXT/pdos]

  1. *******************************************************************************
  2. *
  3. * Menus -- Version 3.0
  4. *
  5. * (C)  Copyright Apple Computer, Inc. 1988-1990
  6. * All rights reserved.
  7. *
  8. * Developer Technical Support Apple II Sample Code
  9. *
  10. * by Jim Mensch
  11. *
  12. * Sample Application that demonstrates the use of many menu manager
  13. * calls. It Shows how to add or remove whole menus or menu items, and how to
  14. * manipulate existing items.
  15. * It also demonstrates how to create a custom menu and handle user 
  16. * interactions with it. The custom menu can be removed from this program and 
  17. * incorporated inside your own applications. The custom menu is a color menu
  18. * that allows the user to select one of 4 colors.
  19. *
  20. *******************************************************************************
  21.                     eject
  22.                     
  23. **********************************************************************
  24. *                                                                    *
  25. *             Apple IIGS Source Code Sampler, Volume I               *
  26. *                                                                    *
  27. *             Copyright (c) Apple Computer, Inc. 1988-1990           *
  28. *                       All Rights Reserved                          *
  29. *                                                                    *
  30. *            Written by Apple II Developer Tech Support              *
  31. *                                                                    *
  32. *                                                                    *
  33. *                                                                    *
  34. *  ----------------------------------------------------------------  *
  35. *                                                                    *
  36. *     This program and its derivatives are licensed only for         *
  37. *     use on Apple computers.                                        *
  38. *                                                                    *
  39. *     Works based on this program must contain and                   *
  40. *     conspicuously display this notice.                             *
  41. *                                                                    *
  42. *     This software is provided for your evaluation and to           *
  43. *     assist you in developing software for the Apple IIGS           *
  44. *     computer.                                                      *
  45. *                                                                    *
  46. *     DISCLAIMER OF WARRANTY                                         *
  47. *                                                                    *
  48. *     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT                       *
  49. *     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,               *
  50. *     WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS             *
  51. *     FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO             *
  52. *     THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH            *
  53. *     YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND            *
  54. *     NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)               *
  55. *     ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,             *
  56. *     REPAIR OR CORRECTION.                                          *
  57. *                                                                    *
  58. *     Apple does not warrant that the functions                      *
  59. *     contained in the Software will meet your requirements          *
  60. *     or that the operation of the Software will be                  *
  61. *     uninterrupted or error free or that defects in the             *
  62. *     Software will be corrected.                                    *
  63. *                                                                    *
  64. *     SOME STATES DO NOT ALLOW THE EXCLUSION                         *
  65. *     OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY              *
  66. *     NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC            *
  67. *     LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS                *
  68. *     WHICH VARY FROM STATE TO STATE.                                *
  69. *                                                                    *
  70. *                                                                    *
  71. **********************************************************************
  72.  
  73.                     case   on
  74.  
  75.                     copy 2/ainclude/E16.Quickdraw
  76.                     copy 2/ainclude/E16.Memory
  77.                     copy 2/ainclude/E16.Event
  78.                     copy 2/ainclude/E16.Menu
  79.                     copy 2/ainclude/E16.Window
  80.                     copy 2/ainclude/E16.Dialog
  81.                     mcopy macros/menus.macros
  82.                     
  83. DPHandle            gequ 0
  84. DPPointer           gequ DPHandle+4
  85. DeRef               gequ DPPointer+4
  86. LastTick            gequ 10
  87. temp1               gequ 12
  88. temp2               gequ 14
  89. LinePt              gequ 16
  90. ScreenTab           gequ 20
  91. CustomMHandle       gequ 24
  92. CustomMPtr          gequ 28
  93.  
  94. MarkItem            gequ 258
  95. testINum            gequ 267
  96. AddMenuItem         gequ 263
  97. DelMenuItem         gequ 265
  98. AddAMenu            gequ 264
  99. DelAMenu            gequ 266
  100. CMenuNums           gequ 273
  101.  
  102. ScreenMode          gequ mode320
  103. ScreenWidth         gequ 320
  104. ; menu record offsets
  105.  
  106. MRMenuFlag          gequ $0A
  107. MRMenuTWidth        gequ $0E
  108. MRMenuTPtr          gequ $10
  109.  
  110.                     EJECT
  111. *******************************************************************************
  112. *
  113. Menus               start
  114. *
  115. * Description:      Main code of the program. This routine calls all the other
  116. *                   main program parts in order.
  117. *
  118. *
  119. * Inputs:           None
  120. *
  121. * Outputs:          None
  122. *
  123. * External Refs:
  124. *                   Import QuitParms
  125. *                   Import InitTools
  126. *                   Import InitApp
  127. *                   Import EventLoop
  128. *                   Import CloseTools
  129. *
  130. * Entry Points:
  131. *
  132. *******************************************************************************
  133.  
  134.                     jsr InitTools
  135.                     jsr InitApp
  136.  
  137.                     _ShowCursor
  138.  
  139.                     jsr EventLoop
  140.                     jsr CloseTools
  141.  
  142.                     _Quit QuitParms
  143.  
  144.                     end
  145.  
  146.                     EJECT
  147. *******************************************************************************
  148. *
  149. Globals             data
  150. *
  151. * Description:      This area contains data used in all routines of the program
  152. *                   it also contains some data structures used by Menus.Init
  153. *
  154. *
  155. * Inputs:           None
  156. *
  157. * Outputs:          None
  158. *
  159. * External Refs:
  160. *                   Export QuitParms
  161. *                   Import CustomMenu
  162. *
  163. * Entry Points:
  164. *
  165. *******************************************************************************
  166. *
  167. * standard global data here
  168. *
  169. *******************************************************************************
  170. TitleString         str 'Apple IIgs Menus Demo'
  171. AutString           str 'By Mensch / Copyright (c)'
  172. CRString            str '1988-1990 Apple Computer'
  173. VersString          str 'Version: 3.0'
  174.  
  175. MenuHeight          ds 2                ; Stored height of menu bar
  176. MyID                ds 2                ; application ID
  177. MyDP                ds 2                ; My zero page storage
  178.  
  179. QuitFlag            ds 2
  180. QuitParms           dc i4'0'            ; Pathname of next app
  181.                     dc i2'$00'          ; flags
  182. EventRecord         ANOP
  183. EventWhat           ds 2
  184. EventMessage        ds 4
  185. EventWhen           ds 4
  186. EventWhere          ds 4
  187. EventModifiers      ds 2
  188. TaskData            ds 4
  189. TaskMask            dc i4'$0000FFFF'
  190.  
  191. *
  192. * Application specific data goes here
  193. *
  194.  
  195. AppMenu             dc c'$$@\XN1',i1'$0D'
  196.                     dc c'--About Menus...\N256V',i1'$0D'
  197.                     dc c'.'
  198. FileMenu            dc c'$$ File \N2',i1'$0D'
  199.                     dc c'--Quit\N257*Qq',i1'$0D'
  200.                     dc c'.'
  201. MenuMenu            dc c'$$ Actions \N3',i1'$0D'
  202.                     dc c'--Mark Item\N258*Cc',i1'$0D'
  203.                     dc c'--Set Blinks\N259',i1'$0D'
  204.                     dc c'--Change Test Item Text\N260',i1'$0D'
  205.                     dc c'--Disable Test Item\N261',i1'$0D'
  206.                     dc c'--Enable Test Item\N262',i1'$0D'
  207.                     dc c'--Add a Menu Item\N263',i1'$0D'
  208.                     dc c'--Add a Menu\N264D',i1'$0D'
  209.                     dc c'--Delete a Menu Item\N265D',i1'$0D'
  210.                     dc c'--Delete a Menu\N266V',i1'$0D'
  211.                     dc c'--Test Item\N267',i1'$0D'
  212.                     dc c'.'
  213.  
  214. CMDTitle            dc c'$$ Custom \N5',i1'$0D',i1'$00'
  215.                     dc c'.'
  216.                     
  217. TestMenu            dc c'$$ Test \N4',i1'$0D'
  218.                     dc c'--Normal\N268',i1'$0d'
  219.                     dc c'--Bold\N269B',i1'$0D'
  220.                     dc c'--Disabled\N270D',i1'$0d'
  221.                     dc c'--Italics\N271I',i1'$0d'
  222.                     dc c'--Color Replace Highlight\N272X',i1'$0d'
  223.                     dc c'.'
  224.  
  225. Rect                ds 8
  226. MyRect              ds 8
  227.  
  228. TestMHandle         ds 4
  229.  
  230. CMDMenuProc         dc i4'CustomMenu'   ; custom menu proc
  231. PatTable            dc i4'MyPattern1,MyPattern2,MyPattern3,MyPattern4'
  232.  
  233. MyPattern1          dc i1'$55,$55,$55,$55' ; patterns used by                   the custom menu
  234.                     dc i1'$55,$55,$55,$55' ; when the user selects a color
  235.                     dc i1'$55,$55,$55,$55' ; these are the patterns that are
  236.                     dc i1'$55,$55,$55,$55' ; used to set the menu bar color
  237.                     dc i1'$55,$55,$55,$55'
  238.                     dc i1'$55,$55,$55,$55'
  239.                     dc i1'$55,$55,$55,$55'
  240.                     dc i1'$55,$55,$55,$55'
  241. MyPattern2          dc i1'$77,$77,$77,$77'
  242.                     dc i1'$77,$77,$77,$77'
  243.                     dc i1'$77,$77,$77,$77'
  244.                     dc i1'$77,$77,$77,$77'
  245.                     dc i1'$77,$77,$77,$77'
  246.                     dc i1'$77,$77,$77,$77'
  247.                     dc i1'$77,$77,$77,$77'
  248.                     dc i1'$77,$77,$77,$77'
  249. MyPattern3          dc i1'$44,$44,$44,$44'
  250.                     dc i1'$44,$44,$44,$44'
  251.                     dc i1'$44,$44,$44,$44'
  252.                     dc i1'$44,$44,$44,$44'
  253.                     dc i1'$44,$44,$44,$44'
  254.                     dc i1'$44,$44,$44,$44'
  255.                     dc i1'$44,$44,$44,$44'
  256.                     dc i1'$44,$44,$44,$44'
  257. MyPattern4          dc i1'$22,$22,$22,$22'
  258.                     dc i1'$22,$22,$22,$22'
  259.                     dc i1'$22,$22,$22,$22'
  260.                     dc i1'$22,$22,$22,$22'
  261.                     dc i1'$22,$22,$22,$22'
  262.                     dc i1'$22,$22,$22,$22'
  263.                     dc i1'$22,$22,$22,$22'
  264.                     dc i1'$22,$22,$22,$22'
  265.                     end
  266.  
  267.  
  268.                     EJECT
  269. *******************************************************************************
  270. *
  271. CustomMenu          start
  272. *
  273. * Description:      This is the whole custom menu routine. This routine takes care
  274. *                   of all drawing and selecting of the custom menu. It starts out 
  275. *                   with a dispatch routine to dispatch the operations the menu
  276. *                   manager requests.
  277. *
  278. *
  279. * Inputs:           None
  280. *
  281. * Outputs:          None
  282. *
  283. * External Refs:    None
  284. *
  285. * Entry Points:     None
  286. *
  287. *******************************************************************************
  288.                     using Globals
  289. local               equ 8               ; number of bytes of local stack frame
  290. Temp                equ $01
  291. mPtr                equ $04
  292. RetAddr             equ $01+local       ; stack frame constants
  293. MenuParam           equ $04+local
  294. yHitPt              equ $06+local
  295. xHitPt              equ $08+local
  296. rectPtr             equ $0A+local
  297. mHandle             equ $0E+local
  298. menuMessage         equ $12+local
  299. Result              equ $14+local
  300.  
  301. MaxItems            equ 5               ; number of menu items +1
  302. CMenuWidth          equ 50              ; menu is 50 x 50 pixels
  303. CMenuHeight         equ 50
  304.  
  305.                     tdc                 ; save the DPage
  306.                     sta >tempDPage      ; to a temp value
  307.                     tsc                 ; get the stack pointer
  308.                     sta >tempStack      ; and save it...
  309.  
  310.                     sec
  311.                     sbc #local          ; add in our temp data storage
  312.                     tcs                 ; set it as the stack pointer
  313.                     tcd                 ; and as the Dpage register
  314.  
  315.                     phb                 ; save the data bank register
  316.                     phk                 ; and switch to current bank
  317.                     plb
  318.  
  319.                     stz Result          ; zero out result ahead of time
  320.  
  321.                     lda [mHandle]       ; dereference the menu handle
  322.                     sta mPtr
  323.                     ldy #2
  324.                     lda [mHandle],y
  325.                     sta mPtr+2
  326.  
  327.                     lda menuMessage     ; now handle the message
  328.                     asl a
  329.                     tax
  330.                     jmp (CMJumpTab,x)
  331.  
  332. CMenuDone           ANOP
  333.                     plb                 ; restore the data bank register
  334.                     lda >tempDPage      ; restore Dpage
  335.                     tcd
  336.                     lda >tempStack      ; restore stack pointer
  337.                     tcs
  338.                     ShortM              ; now discard parameter list
  339.                     pla                 ; save the return address in a and X
  340.                     plx
  341.  
  342.                     ply                 ; discard all the parameters
  343.                     ply
  344.                     ply
  345.                     ply
  346.                     ply
  347.                     ply
  348.                     ply
  349.                     ply
  350.  
  351.                     phx                 ; restore the return addres previously saved
  352.                     pha
  353.                     LongM
  354.  
  355.                     rtl
  356.  
  357. *
  358. *   CMGetID -   accepts a menu internal ID number and converts it into an
  359. *               application menu ID number. This is the number that is given
  360. *               to the application by taskmaster when you have completed
  361. *               your menu selection.
  362. *
  363.  
  364. CMGetID             ANOP
  365.                     lda MenuParam       ; get the internal item ID
  366.                     clc                 ; and add application offset to
  367.                     adc #CMenuNums      ; create actual item number
  368.                     sta Result          ; save the result
  369.                     brl CMenuDone       ; and return back to dispatch routine
  370.  
  371. *
  372. *   CMDrawI -   Called when the menu manager wants to Hilight/unhilight a
  373. *               menu item in your menu ( when mouse is dragged onto or off
  374. *               of the item ) This routine calls either DrawItem or HilighItem
  375. *               depending on the request
  376. *
  377.  
  378. CMDrawI             ANOP
  379.                     lda MenuParam       ; get the number
  380.                     bmi CMDIHiLite      ; if high bit set then highlite
  381.                     jsr DrawItem        ; else just draw it
  382.                     brl CMenuDone
  383. CMDIHiLite          and #$7FFF          ; strip the high bit
  384.                     jsr InvertItem
  385.                     brl CMenuDone
  386.  
  387. *
  388. *   CMDrawT -   The menu manager asks for this call when it is drawing the
  389. *               menu title. I want the menu manager to draw my title
  390. *               so I just pass back a false result and the menu mgr handles
  391. *               it for me
  392.  
  393. CMDrawT             ANOP
  394.                     stz Result          ; false to have menu mgr do this...
  395.                     brl CMenuDone
  396.  
  397. *
  398. *   CMSize -    Calculate values for menuWidth and menuHeight in the menu record
  399. *
  400.  
  401. CMSize              ANOP
  402.                     ldy #omenuWidth     ; offset into menu record
  403.                     lda [mPtr],y        ; get the width parameter
  404.                     bne CMS0010         ; if non-zero do not change the value           
  405.                     lda #CMenuWidth     ; save # of pixels wide
  406.                     sta [mPtr],y
  407. CMS0010             ldy #omenuHeight    ; offset into menu record for height
  408.                     lda [mPtr],y        ; load the height
  409.                     bne CMS0020         ; if non-zero do not change them
  410.                     lda #CMenuHeight
  411.                     sta [mPtr],y
  412. CMS0020             ANOP
  413.                     brl CMenuDone
  414.  
  415. *
  416. *   CMChoose -  Routine called when user mouse location changes. This routine
  417. *               should return  in the result the internal ID number of the
  418. *               item the mouse point is currently over. If no item selected
  419. *               leave the result alone.
  420. *
  421.  
  422. CMChoose            ANOP
  423.                     lda #1              ; initialize the counter at 1
  424.                     sta itemTemp        ; This will count thru each menu item to test
  425. CMC0010             ANOP
  426.                     lda itemTemp        ; get the item number to test
  427.                     cmp #MaxItems       ; are we done yet???
  428.                     bge CMCDone         ; if so then quit...
  429.                     jsr TestHit         ; test each item for a hit
  430.                     bne CMCHit          ; if non-zero got a hit
  431.                     inc itemTemp        ; bump the counter
  432.                     bra CMC0010         ; and try the next item
  433. CMCHit              lda itemTemp        ; got a hit so return the number
  434.                     ora #$8000          ; set high order bit to flag as selected
  435.                     sta Result          ; and save it as the result
  436. CMCDone             ANOP
  437.                     brl CMenuDone       ; and leave
  438.  
  439. *
  440. *   CMDraw -    This routine draws the contents of the custom menu when the
  441. *               menu is first selected.
  442. *
  443.  
  444. CMDraw              ANOP
  445.  
  446.                     lda #1              ; draw item 1
  447.                     jsr DrawItem
  448.  
  449.                     lda #2
  450.                     jsr DrawItem
  451.  
  452.                     lda #3
  453.                     jsr DrawItem
  454.  
  455.                     lda #4
  456.                     jsr DrawItem
  457.  
  458.                     brl CMenuDone
  459.  
  460. *
  461. * SetUpRect - sets tempRect equal to the rectangle of the custom menu item
  462. * in <A>. This routine is used by drawItem,InvertItem and TestHit
  463. *
  464.  
  465. SetUpRect           ANOP
  466.                     dec a               ; item numbers based off of 1 not 0
  467.                     asl a               ; item number *8 for offset into rect table
  468.                     asl a
  469.                     asl a
  470.                     tax                 ; place it in x to use as an index
  471.  
  472.                     ldy #2              ; get values to offset rectangle by
  473.                     lda [rectPtr],y     ; wmgr rectangle left
  474.                     sta tempPt+2        ; and save it for use later
  475.                     lda [rectPtr]       ; now get the top
  476.                     sta tempPt
  477.  
  478.                     lda MyRect1,x       ; load in the top
  479.                     clc                 ; and add the offset
  480.                     adc tempPt
  481.                     sta tempRect        ; and store it 
  482.  
  483.                     lda MyRect1+2,x     ; load in the left
  484.                     clc
  485.                     adc tempPt+2        ; offset it
  486.                     sta tempRect+2
  487.  
  488.                     lda MyRect1+4,x     ; Load the bottom
  489.                     clc
  490.                     adc tempPt
  491.                     sta tempRect+4
  492.  
  493.                     lda MyRect1+6,x     ; and finally the right
  494.                     clc
  495.                     adc tempPt+2
  496.                     sta tempRect+6
  497.  
  498.                     rts
  499.  
  500. *
  501. *   DrawItem -  Draw the menu item contained in A
  502. *
  503.  
  504. DrawItem            ANOP                ; draws item specified by a
  505.                     sta itemTemp
  506.                     jsr SetUpRect
  507.  
  508.                     PushLong #tempRect
  509.                     lda PatTable+2      ; get high word of pattern addr
  510.                     pha
  511.                     lda itemTemp        ; push pattern ptr low byte
  512.                     dec a               ; item# based from 1 not 0
  513.                     asl a               ; multiply by 4 and use it as a
  514.                     asl a               ; table offset
  515.                     tax
  516.                     lda PatTable,x
  517.                     pha
  518.                     _FillRect
  519.                     rts
  520.  
  521. *
  522. *   InvertItem -    Invert an Item to show it is selected
  523. *
  524.  
  525. InvertItem          ANOP
  526.                     jsr SetUpRect
  527.  
  528.                     PushLong #tempRect
  529.                     _InvertRect
  530.                     rts
  531.  
  532. *
  533. *   TestHit -   With an Item number passed in A test to see if 
  534. *               the cursor is over the Item. If so return true, if not return false
  535. *
  536.  
  537. TestHit             ANOP
  538.                     jsr SetUpRect       ; create rectangle to test
  539.  
  540.                     lda yHitPt          ; create a point from the passed data
  541.                     sta tempPt          ; since we must pass this data by pointer
  542.                     lda xHitPt          ; to PtInRect, we must move the data from
  543.                     sta tempPt+2        ; the stack frame into temp storage
  544.  
  545.                     PushWord #0         ; room for result
  546.                     PushLong #tempPt    ; current cursor location
  547.                     PushLong #tempRect  ; item rectangle to test
  548.                     _PtInRect
  549.                     pla                 ; return result in A
  550.  
  551.                     rts
  552.  
  553. *
  554. *   Data storage area for the custom menu routine
  555. *
  556.  
  557. tempStack           ds 2                ; storage for Stack and Dpage registers
  558. tempDPage           ds 2
  559. CMJumpTab           ANOP                ; jump table for the dispatch routine
  560.                     dc i2'CMDraw'       ; mDrawMenu routine
  561.                     dc i2'CMChoose'     ; mChoose routine
  562.                     dc i2'CMSize'       ; mSize routine
  563.                     dc i2'CMDrawT'      ; mDrawTitle routine
  564.                     dc i2'CMDrawI'      ; mDrawMItem Routine
  565.                     dc i2'CMGetID'      ; mGetMItemID routine
  566.  
  567. MyRect1             dc i2'3,3,23,23'    ; rectangles for the 4 menu items
  568. MyRect2             dc i2'25,3,45,23'
  569. MyRect3             dc i2'3,25,23,45'
  570. MyRect4             dc i2'25,25,45,45'
  571. tempRect            ds 8                ; temp rectangle to use in various places
  572. tempPt              ds 4                ; temp point to use in various places
  573. itemTemp            ds 2
  574.  
  575.                     end
  576.  
  577.                     EJECT
  578. *******************************************************************************
  579. *
  580. InitApp             start
  581. *
  582. * Description:      Initialize my menu bar and the quit flags. This demonstrates how
  583. *                   to install a custom menu!
  584. *
  585. *
  586. * Inputs:           None
  587. *
  588. * Outputs:          None
  589. *
  590. * External Refs:
  591. *                   Import ColorSel
  592. * Entry Points:
  593. *
  594. *******************************************************************************
  595.                     using Globals
  596.  
  597.                     Stz QuitFlag        ; initialize the quit flag
  598.  
  599.  
  600.                     PushLong #0         ; room for result
  601.                     PushLong #CMDTitle  ; our custom menu
  602.                     _NewMenu            ; now create a new menu
  603.  
  604.                     lda 1,s             ; get menu pointer for later use
  605.                     sta CustomMHandle   ; while leaving them on the stack   
  606.                     lda 3,s
  607.                     sta CustomMHandle+2
  608.  
  609.                     lda [CustomMHandle] ; dereference the menu handle 
  610.                     sta CustomMPtr
  611.                     ldy #2
  612.                     lda [CustomMHandle],y
  613.                     sta CustomMPtr+2
  614.  
  615.                     lda CMDMenuProc     ; now fix it so that this is a cust menu
  616.                     ldy #omenuProc      ; by setting the menu proc to point to 
  617.                     sta [CustomMPtr],y  ; our custom procedure
  618.                     lda CMDMenuProc+2
  619.                     iny
  620.                     iny
  621.                     sta [CustomMPtr],y
  622.  
  623.                     ldy #omenuFlag
  624.                     lda [CustomMPtr],y
  625.                     ora #menuCustom
  626.                     sta [CustomMPtr],y
  627.  
  628.  
  629. ; Set up custom menu info here ....
  630.  
  631.                     PushWord #0         ; menu handle already on stack insert 
  632.                     _InsertMenu         ; it before all other menus
  633.  
  634.                     PushLong #0
  635.                     PushLong #TestMenu
  636.                     _NewMenu
  637.  
  638.                     lda 1,s             ; get menu pointer for later use
  639.                     sta TestMHandle     ; and leave it on the stack
  640.                     lda 3,s
  641.                     sta TestMHandle+2
  642.  
  643.                     PushWord #0
  644.                     _InsertMenu
  645.  
  646.                     PushLong #0
  647.                     PushLong #MenuMenu
  648.                     _NewMenu
  649.                     PushWord #0
  650.                     _InsertMenu
  651.  
  652.                     PushLong #0
  653.                     PushLong #FileMenu
  654.                     _NewMenu
  655.                     PushWord #0
  656.                     _InsertMenu
  657.  
  658.                     PushLong #0
  659.                     PushLong #AppMenu
  660.                     _NewMenu
  661.                     PushWord #0
  662.                     _InsertMenu
  663.  
  664.                     PushWord #1         ; Add NDA's
  665.                     _FixAppleMenu
  666.  
  667.                     PushWord #0
  668.                     _FixMenuBar
  669.                     Pla
  670.                     sta MenuHeight
  671.  
  672.                     PushWord #$00F5     ; white-blue/red not selected colors
  673.                     PushWord #$0010     ; blue/red-black selected colors
  674.                     PushWord #$00E0     ; yellowgreen outline
  675.                     _SetBarColors       ; now set the bar colors
  676.  
  677.                     lda #274            ; Get the inverse color the the Apple
  678.                     sta TaskData        ; Menu set up correctly.
  679.                     jsr ColorSel
  680.  
  681.                     rts
  682.                     end
  683.  
  684.                     EJECT
  685. *******************************************************************************
  686. *
  687. EventLoop           start
  688. *
  689. * Description:      The event loop recieves events and dispatches them. When
  690. *                   the quitflag is non-zero, it exits.
  691. *
  692. * Inputs:           None
  693. *
  694. * Outputs:          None
  695. *
  696. * External Refs:
  697. *                   Import MenuSelect
  698. *                   Import Ignore
  699. *
  700. * Entry Points:
  701. *
  702. *******************************************************************************
  703.                     using Globals
  704.  
  705.                     PushWord #0         ; room for result
  706.                     PushWord #everyEvent ; handle all events
  707.                     PushLong #EventRecord ; place event data here
  708.                     _TaskMaster
  709.  
  710.                     pla                 ; get the event type here
  711.                     beq EventLoop       ; remove if you want to use null events
  712.                     asl A               ; multiply by two
  713.                     tax                 ; and do a table dispatch just like menu select
  714.                     jsr (TaskTable,x)
  715.  
  716.                     lda QuitFlag        ; test to see if user selected quit
  717.                     beq EventLoop       ; if not just go get another event
  718.  
  719.                     rts                 ; if so, then end the event loop
  720.  
  721. TaskTable           dc i2'Ignore'       ; 0 Null
  722.                     dc i2'Ignore'       ; 1 MouseDown
  723.                     dc i2'Ignore'       ; 2 Mouse Up
  724.                     dc i2'Ignore'       ; 3 KeyDown
  725.                     dc i2'Ignore'       ; 4 Undefined
  726.                     dc i2'Ignore'       ; 5 AutoKey
  727.                     dc i2'Ignore'       ; 6 Update
  728.                     dc i2'Ignore'       ; 7 undefined
  729.                     dc i2'Ignore'       ; 8 activate
  730.                     dc i2'Ignore'       ; 9 Switch
  731.                     dc i2'Ignore'       ; 10 desk acc
  732.                     dc i2'Ignore'       ; 11 device driver
  733.                     dc i2'Ignore'       ; 12 ap
  734.                     dc i2'Ignore'       ; 13 ap
  735.                     dc i2'Ignore'       ; 14 ap
  736.                     dc i2'Ignore'       ; 15 ap
  737.                     dc i2'Ignore'       ; TASK 0 indesk
  738.                     dc i2'MenuSelect'   ; TASK 1 in menuBar
  739.                     dc i2'Ignore'       ; TASK 2 in system window
  740.                     dc i2'Ignore'       ; TASK 3 in content
  741.                     dc i2'Ignore'       ; TASK 4 in Drag
  742.                     dc i2'Ignore'       ; TASK 5 in grow
  743.                     dc i2'Ignore'       ; TASK 6 in goaway
  744.                     dc i2'Ignore'       ; TASK 7 in zoom
  745.                     dc i2'Ignore'       ; TASK 8 in info bar
  746.                     dc i2'Ignore'       ; TASK 9 in special menu
  747.                     dc i2'Ignore'       ; TASK 10 in NDA
  748.                     dc i2'Ignore'       ; TASK 11 in frame
  749.                     dc i2'Ignore'       ; TASK 12 in drop
  750.                     end
  751.  
  752.                     EJECT
  753. *******************************************************************************
  754. *
  755. MenuSelect          start
  756. *
  757. * Description:      This routine is called when taskmaster returns 
  758. *                   a menu event. This routine takes the menu item that
  759. *                   was hit and calculates an offset into the menu
  760. *                   dispatch table. It then calls that routine
  761. *
  762. *
  763. * Inputs:           None
  764. *
  765. * Outputs:          None
  766. *
  767. * External Refs:
  768. *                   Import DoAbout
  769. *                   Import DoQuit
  770. *                   Import SetMark
  771. *                   Import SetBlink
  772. *                   Import SetName
  773. *                   Import DisableIt
  774. *                   Import EnableIt
  775. *                   Import DoAdd
  776. *                   Import DoAddM
  777. *                   Import DoRemove
  778. *                   Import DoRemoveM
  779. *                   Import ColorSel
  780. *                   Import Ignore
  781. *
  782. * Entry Points:
  783. *
  784. *******************************************************************************
  785.                     using Globals
  786.  
  787.                     lda TaskData        ; get the menu number hit
  788.                     sec                 ; subtract 250 ( that is where our menu numbers
  789.                     sbc #256            ; start)
  790.                     asl a               ; multiply it by 2 ( table has 2 byte entries )
  791.                     tax                 ; use as an index
  792.                     jsr (menuTable,x)   ; and jump to the routine to handle that item
  793.  
  794.                     PushWord #0         ; unhilight the menu bar now
  795.                     PushWord TaskData+2 ; menu number that was hit
  796.                     _HiLiteMenu
  797.  
  798.                     rts
  799. ;
  800. ; the menu table should contain one entry for each menu item
  801. ;
  802. menuTable           dc i2'DoAbout'      ; 256 About Menus
  803.                     dc i2'DoQuit'       ; 257 Quit
  804.                     dc i2'SetMark'      ; 258 Mark test item
  805.                     dc i2'SetBlink'     ; 259 Set Blink rate
  806.                     dc i2'SetName'      ; 260 Change test item text
  807.                     dc i2'DisableIt'    ; 261 Disable test item
  808.                     dc i2'EnableIt'     ; 262 enable test item
  809.                     dc i2'DoAdd'        ; 263 add menu item
  810.                     dc i2'DoAddM'       ; 264 add menu
  811.                     dc i2'DoRemove'     ; 265 delete menu item
  812.                     dc i2'DoRemoveM'    ; 266 delete menu
  813.                     dc i2'Ignore'       ; 267 test item
  814.                     dc i2'Ignore'       ; 268 normal
  815.                     dc i2'Ignore'       ; 269 bold
  816.                     dc i2'Ignore'       ; 270 disabled
  817.                     dc i2'Ignore'       ; 271 italics
  818.                     dc i2'Ignore'       ; 272 color replace
  819.                     dc i2'Ignore'       ; 273 Not implemented
  820.                     dc i2'ColorSel'     ; 274 color selection
  821.                     dc i2'ColorSel'     ; 275 color selection
  822.                     dc i2'ColorSel'     ; 276 color selection
  823.                     dc i2'ColorSel'     ; 277 Color selection
  824.  
  825.                     end
  826.  
  827.                     EJECT
  828. *******************************************************************************
  829. *
  830. SetMark             start
  831. *
  832. * Description:      Demonstrate how to Mark/UnMark an item.
  833. *
  834. *
  835. * Inputs:           None
  836. *
  837. * Outputs:          None
  838. *
  839. * External Refs:
  840. *
  841. * Entry Points:
  842. *
  843. *******************************************************************************
  844.  
  845.                     PushWord #0         ; room for result
  846.                     PushWord #MarkItem  ; test menu item number
  847.                     _GetMItemMark
  848.  
  849.                     pla                 ; get current mark status
  850.                     bne SMUnMark        ; if not zero then unmark it
  851.  
  852.                     PushWord #18        ; else mark with ascii 18
  853.                     PushWord #MarkItem
  854.                     _SetMItemMark
  855.                     rts
  856.  
  857. SMUnMark            ANOP
  858.                     PushWord #0         ; Unmark the test item
  859.                     PushWord #MarkItem
  860.                     _SetMItemMark
  861.                     rts
  862.                     end
  863.  
  864.                     EJECT
  865. *******************************************************************************
  866. *
  867. EnableIt            start
  868. *
  869. * Description:      Demonstrate how to enable a menu item
  870. *
  871. *
  872. * Inputs:           None
  873. *
  874. * Outputs:          None
  875. *
  876. * External Refs:    None
  877. *
  878. * Entry Points:
  879. *
  880. *******************************************************************************
  881.  
  882.                     PushWord #testINum
  883.                     _EnableMItem
  884.                     rts
  885.                     end
  886.  
  887.  
  888. *******************************************************************************
  889. *
  890. DisableIt           start
  891. *
  892. * Description:      Demonstrate how to disable a menu item
  893. *
  894. *
  895. * Inputs:           None
  896. *
  897. * Outputs:          None
  898. *
  899. * External Refs:    None
  900. *
  901. * Entry Points:     None
  902. *
  903. *******************************************************************************
  904.                     PushWord #testINum
  905.                     _DisableMItem
  906.                     rts
  907.                     end
  908.  
  909.                     EJECT
  910. *******************************************************************************
  911. *
  912. SetName             start
  913. *
  914. * Description:      Change the name of the test item. This routine will
  915. *                   toggle between the names 'Test Item' and 'Improved Test Item'
  916. *                   to show how to change an Item name.
  917. *
  918. * Inputs:           None
  919. *
  920. * Outputs:          None
  921. *
  922. * External Refs:
  923. *
  924. * Entry Points:
  925. *
  926. *******************************************************************************
  927.                     lda NameFlag        ; test state of current name if non then
  928.                     beq SN0010          ; name still original/ needs changing
  929.  
  930.                     stz NameFlag        ; zero name flag to denote alt name
  931.                     PushLong #NewName   ; Set the new name
  932.                     PushWord #testINum
  933.                     _SetMItemName
  934.                     rts
  935. SN0010              ANOP
  936.                     lda #1              ; set flag to denote original item displayed
  937.                     sta NameFlag
  938.                     PushLong #OrigName
  939.                     PushWord #testINum
  940.                     _SetMItemName
  941.                     rts
  942. NewName             str 'Improved test item'
  943. OrigName            str 'Test Item'
  944. NameFlag            dc i2'1'
  945.                     end
  946.  
  947.                     EJECT
  948. *******************************************************************************
  949. *
  950. SetBlink            start
  951. *
  952. * Description:      Changes the number of times selected menu items blink.
  953. *
  954. *
  955. * Inputs:           None
  956. *
  957. * Outputs:          None
  958. *
  959. * External Refs:
  960. *
  961. * Entry Points:
  962. *
  963. *******************************************************************************
  964.                     PushWord BRate
  965.                     _SetMItemBlink
  966.  
  967.                     lda BRate
  968.                     eor #$0003          ; xor with 3 to swap between 1 and 2
  969.                     sta BRate
  970.  
  971.                     rts
  972. BRate               dc i2'1'            ; the next blink rate
  973.                     end
  974.  
  975.                     EJECT
  976. *******************************************************************************
  977. *
  978. ColorSel            start
  979. *
  980. * Description:      This routine will be called when the user selects one of 
  981. *                   the custom menu items. It will change the menu bar color
  982. *                   to the color selected by the user.
  983. *
  984. *
  985. * Inputs:           TaskData - Menu item selected
  986. *
  987. * Outputs:          None
  988. *
  989. * External Refs:    None
  990. *
  991. * Entry Points:     None
  992. *
  993. *******************************************************************************
  994.                     using Globals
  995.  
  996.                     lda TaskData        ; get the menu number
  997.                     sec                 ; and make it a number between 0 and 3
  998.                     sbc #CMenuNums+1    ; by subtracting the selection offset
  999.                     asl a               ; multiply by 4 to use as a table offset
  1000.                     asl a
  1001.                     tax
  1002.                     lda PatTable,x      ; get address of pattern
  1003.                     sta DeRef           ; and use it as a pointer
  1004.                     lda (DeRef)         ; get the selected color
  1005.                     and #$000F          ; strip off high bytes
  1006.                     ora #$00F0          ; set nibble to white
  1007.                     pha                 ; set menu colors to white/selected color
  1008.  
  1009.                     PushWord #$0040     ; blue/black selected colors
  1010.                     PushWord #$0020     ; brown outline
  1011.                     _SetBarColors
  1012.  
  1013.                     _DrawMenuBar
  1014.  
  1015.                     rts
  1016.                     end
  1017.                     
  1018.                     EJECT
  1019. *******************************************************************************
  1020. *
  1021. Ignore              start
  1022. *
  1023. * Description:      This routine is called for all events and menu selection
  1024. *                   that are not handled by this program. Like the name says
  1025. *                   it ignores them.
  1026. *
  1027. *
  1028. * Inputs:           None
  1029. *
  1030. * Outputs:          None
  1031. *
  1032. * External Refs:
  1033. *
  1034. * Entry Points:
  1035. *
  1036. *******************************************************************************
  1037.                     rts
  1038.                     end
  1039.  
  1040.  
  1041. *******************************************************************************
  1042. *
  1043. DoQuit              start
  1044. *
  1045. * Description:      This routine stores a non-zero value in the quit flag to
  1046. *                   notify the event loop that the user wants to stop the
  1047. *                   program.
  1048. *
  1049. *
  1050. * Inputs:           None
  1051. *
  1052. * Outputs:          None
  1053. *
  1054. * External Refs:
  1055. *
  1056. * Entry Points:
  1057. *
  1058. *******************************************************************************
  1059.                     using Globals
  1060.  
  1061.                     lda #1
  1062.                     sta QuitFlag
  1063.                     rts
  1064.                     end
  1065.  
  1066.                     EJECT
  1067. *******************************************************************************
  1068. *
  1069. DoAdd               start
  1070. *
  1071. * Description:      Demonstrates hot to Add an Item to an existing menu. 
  1072. *                   After adding the item this routine disables 
  1073. *                   the Add item and enable the delete item.
  1074. *
  1075. *
  1076. * Inputs:           None
  1077. *
  1078. * Outputs:          None
  1079. *
  1080. * External Refs:
  1081. *
  1082. * Entry Points:
  1083. *
  1084. *******************************************************************************
  1085.                     using Globals
  1086.  
  1087.                     PushLong #NewItem   ; Pointer to the new Item
  1088.                     PushWord #$FFFF     ; Insert at end of the menu
  1089.                     PushWord #$03       ; insert into menu 3
  1090.                     _InsertMItem
  1091.  
  1092.                     PushWord #0         ; Call calc Menusize to get menu mgr to
  1093.                     PushWord #0         ; recalc the menu size. 
  1094.                     PushWord #3         ; Use zeros for auto calculation
  1095.                     _CalcMenuSize
  1096.  
  1097.                     PushWord #AddMenuItem ; Now disable the Add item 
  1098.                     _DisableMItem
  1099.  
  1100.                     PushWord #DelMenuItem ; and enable the delete item so the 
  1101.                     _EnableMItem        ; user can get rid of item just added
  1102.  
  1103.                     rts
  1104. NewItem             dc c'--New Item\N318D',i1'$0D' 
  1105.                     end
  1106.  
  1107.                     EJECT
  1108. *******************************************************************************
  1109. *
  1110. DoRemove            start
  1111. *
  1112. * Description:      Demonstrate how to remove an item. The menu item
  1113. *                   for this routine is enabled only after AddItem adds
  1114. *                   an item. This routine disables the delete item and
  1115. *                   re-enables the add item
  1116. *
  1117. *
  1118. * Inputs:           None
  1119. *
  1120. * Outputs:          None
  1121. *
  1122. * External Refs:
  1123. *
  1124. * Entry Points:
  1125. *
  1126. *******************************************************************************
  1127.                     using Globals
  1128.  
  1129.                     PushWord #318       ; item ID of added item
  1130.                     _DeleteMItem
  1131.  
  1132.                     PushWord #0         ; recalc menu size with automatic 
  1133.                     PushWord #0         ; calculation by passing 0's
  1134.                     PushWord #3         ; recalc menu 0
  1135.                     _CalcMenuSize
  1136.  
  1137.                     PushWord #DelMenuItem ; disable this cause now, theres 
  1138.                     _DisableMItem       ; nothing to remove
  1139.  
  1140.                     PushWord #AddMenuItem ; enable this again, so the user 
  1141.                     _EnableMItem        ; can try again
  1142.  
  1143.                     rts
  1144.                     end
  1145.  
  1146.                     EJECT
  1147. *******************************************************************************
  1148. *
  1149. DoRemoveM           start
  1150. *
  1151. * Description:      Demonstrate how to remove an entire menu from the menu bar
  1152. *
  1153. *
  1154. * Inputs:           None
  1155. *
  1156. * Outputs:          None
  1157. *
  1158. * External Refs:
  1159. *
  1160. * Entry Points:
  1161. *
  1162. *******************************************************************************
  1163.                     using Globals
  1164.  
  1165.                     PushWord #4         ; menu number to remove
  1166.                     _DeleteMenu
  1167.  
  1168.                     _DrawMenuBar        ; redraw the menu bar
  1169.  
  1170.                     PushWord #DelAMenu  ; disable this feature and enable Addmenu
  1171.                     _DisableMItem
  1172.  
  1173.                     PushWord #AddAMenu
  1174.                     _EnableMItem
  1175.  
  1176.                     rts
  1177.                     end
  1178.  
  1179.                     EJECT
  1180. *******************************************************************************
  1181. *
  1182. DoAddM              start
  1183. *
  1184. * Description:      Demonstrate how to add a menu to the menu bar.
  1185. *
  1186. *
  1187. * Inputs:           None
  1188. *
  1189. * Outputs:          None
  1190. *
  1191. * External Refs:
  1192. *
  1193. * Entry Points:
  1194. *
  1195. *******************************************************************************
  1196.                     using Globals
  1197.  
  1198.                     PushLong TestMHandle ; handle to the test menu we saved in InitApp
  1199.                     PushWord #3         ; insert after menu 3
  1200.                     _InsertMenu
  1201.  
  1202.                     _DrawMenuBar        ; redraw the menu bar
  1203.  
  1204.                     PushWord #AddAMenu  ; and disable this menu option
  1205.                     _DisableMItem
  1206.  
  1207.                     PushWord #DelAMenu  ; enable the option to delete this menu
  1208.                     _EnableMItem
  1209.  
  1210.                     rts
  1211.                     end
  1212.                     
  1213.                     copy Menus.inits.asm
  1214.  
  1215.                     END
  1216.